<?php
class Pageley_Domain_Validator_Enumeration extends Pageley_Domain_Validator_Abstract {

	private $className;
	private $invalidValueMessage = "error.validation.invalidValue";

	public function __construct($className) {
		$this->className = $className;
	}

	public function validate($value, $propertyName, $object) {
		$errors = new Pageley_Util_ArrayMap();
		if($value !== null && $value !== "") {
            $class = new ReflectionClass($this->className);
    		$classToValidate = $value != null && is_object($value) ? new ReflectionClass(get_class($value)) : null;
    		$invalidValue = $this->rejectIfFalse($class->isInstance($value)
    		    || ($classToValidate != null && $classToValidate->isSubclassOf($class)),
    			$this->invalidValueMessage, array("{field." . $propertyName . "}", $value));
    		if($invalidValue) {
    			$errors->put($propertyName, $invalidValue);
    		}
        }
		return $errors;
	}

	public function setInvalidValueMessage($invalidValueMessage) {
		$this->invalidValueMessage = $invalidValueMessage;
	}


}